<?php

namespace App\Admin\Controllers;

use App\Admin\Metrics\Examples;
use App\Http\Controllers\Controller;
use App\Models\Type;
use Dcat\Admin\Http\Controllers\Dashboard;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    public function index(Content $content)
    {
        return $content
            ->header('团购管理后台')
            ->description('这是后台页面')
            ->body(function (Row $row) {
                $row->column(6, function (Column $column) {
                    $column->row(new Examples\Tickets());
                });

                $row->column(6, function (Column $column) {
                    $column->row(function (Row $row) {
                        $row->column(6, new Examples\NewUsers());
                        $row->column(6, new Examples\NewDevices());
                    });
//                    $column->row(new Examples\Sessions());
                    $column->row(new Examples\ProductOrders());
                });
            });
    }

    /**
     * 一级分类
     */
    public function getType()
    {
        $data = Type::where('pid', 0)->where('deleted_at', '=', null)->get()->toArray();
        foreach ($data as $k => $v) {
            $newData[$k]['id'] = $v['id'];
            $newData[$k]['text'] = $v['type_name'];
        }
        return $newData;
    }

    /**
     * 二级
     */
    public function twoType(Request $request)
    {
        $q = $request->get('q');
        $data = Type::where('pid', $q)->where('deleted_at', '=', null)->get()->toArray();
        foreach ($data as $k => $v) {
            $twoData[$k]['id'] = $v['id'];
            $twoData[$k]['text'] = $v['type_name'];
        }
        return $twoData;
    }
}
